import { oneMinute, oneSecond } from './../constant/time';
import { anHour } from "../constant/time";

// 填充时间为两位数
const padEnd = (num: number | string): string => {
    return String(num).padStart(2, '0');
}
// 毫秒值转时分秒
export const getHhMmDd = (secondVal: number): string => {
    const millisecond = secondVal * oneSecond;
    const hour = Math.floor(millisecond /anHour);
    const minute = Math.floor((millisecond - hour * anHour)/oneMinute);
    const second = Math.floor((millisecond - hour * anHour - minute * oneMinute)/oneSecond);
    const timeArr = [minute, second];
    return timeArr.reduce((t,v, i) => {
        if(i === timeArr.length - 1) {
            return  t += `:${padEnd(v)}`;
        }
        
        t += `${padEnd(v)}`;
        return t;
    }, '');
}